<template>
	<view>
		<my-search @click.native="goToSearch"></my-search>
		<swiper :indicator-dots="true" :autoplay="true" circular="true" :interval="3000" :duration="1000">
			<swiper-item v-for="item in swiperList" :key="item.goods_id">
				<view class="swiper-item">
					<navigator :url="`/subpkg/goods_detail/goods_detail?goods_id=${item.goods_id}`">
						<image :src="item.image_src"></image>
					</navigator>
				</view>
			</swiper-item>
		</swiper>

		<view class="nav-list">
			<view class="nav-item" v-for="(item,index) in navList" :key="index" @click="goToNav(item)">
				<image :src="item.image_src"></image>
			</view>
		</view>

		<view class="floor-list" v-for="(item,index) in floorList" :key="index">
			<view class="floor-item">
				<view class="title">
					<image :src="item.floor_title.image_src" mode=""></image>
				</view>
				<view class="content">
					<image class="first" :src="item.product_list[0].image_src" mode=""></image>
					<view class="small">
						<navigator v-for="(item,index) in item.product_list" :key="index" v-if="index >= 1" :url="item.url">
							<image :src="item.image_src"></image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiperList: [],
				navList: [],
				floorList: []
			};
		},
		methods: {
			goToSearch() {
				console.log(1);
				uni.navigateTo({
					url:'/subpkg/search/search'
				})
			},
			async getSwiper() {
				let res = await uni.$http.get('/api/public/v1/home/swiperdata')
				if (res.statusCode == 200) {
					this.swiperList = res.data.message
				}
			},
			async getNavList() {
				let {
					data
				} = await uni.$http.get('/api/public/v1/home/catitems')
				if (data.meta.status !== 200) return uni.$showMsg
				this.navList = data.message
			},
			goToNav(item) {
				if (item.open_type == 'switchTab') {
					uni.switchTab({
						url: '/pages/cate/cate'
					})
				}
			},
			async getFloorList() {
				let {
					data
				} = await uni.$http.get('/api/public/v1/home/floordata')
				if (data.meta.status !== 200) return uni.$showMsg
				data.message.forEach(item => {
					item.product_list.forEach(item => {
						item.url = `/subpkg/goods_list/goods_list?${item.navigator_url.split('?')[1]}`
					})
				})
				this.floorList = data.message
			},
			goToGoodsList(item) {
				uni.navigateTo({
					url:`${item.url}`
				})
			}
		},
		onLoad() {
			this.getSwiper()
			this.getNavList()
			this.getFloorList()
		}
	}
</script>

<style lang="scss">
	.swiper-item {
		image {
			width: 100%;
		}
	}

	.nav-list {
		margin-top: 10rpx;
		padding: 10rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-around;

		.nav-item {
			flex: 1;
			height: 150rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}
	}

	.floor-item {
		width: 100%;
		padding: 10px;
		box-sizing: border-box;

		.title {
			height: 70rpx;
			padding: 10px;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.content {
			display: flex;

			.first {
				width: 200rpx;
				height: 500rpx;
			}

			.small {

				flex: 1;
				display: flex;
				flex-wrap: wrap;

				image {
					padding: 5rpx;
					box-sizing: border-box;
					width: 250rpx;
					height: 250rpx;
				}
			}
		}
	}
</style>